package io;

import java.io.*;

/**
 * 缓冲字节流:加快读写速度
 * 使用缓冲字节流完成文件复制
 */
public class CopyDemo3 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("641.webp"); //文件输入流---低级流
        BufferedInputStream bis = new BufferedInputStream(fis); //缓冲输入流------高级流
        FileOutputStream fos = new FileOutputStream("641_Jordan.jpg"); //文件输出流------低级流
        BufferedOutputStream bos = new BufferedOutputStream(fos); //缓冲输出流-----------高级流

        long start = System.currentTimeMillis();
        int d;
        while((d = bis.read()) != -1) {
            bos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕, 耗时" + (end - start) + "ms");

        bis.close(); //关闭高级流时, 顺便将低级流关闭了
        bos.close();
    }
}
